We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

how to set table1.column1 = table1.column2 in DbAdapter->update?

code like below:

        $ranks = new Ranks();
        $db = $ranks->getWriteConnection();
        $db->begin();
        $db->update('ranks', array('ranks.last_win','ranks.reward_tag'), array('ranks.win','ranks.week_tag'));
        //$sql = 'UPDATE ranks SET ranks.last_win = ranks.win, extras.reward_tag = extras.week_tag';
        $db->commit();


17.8k
Accepted
answer

After read the official document about Phalcon\Db\RawValue, I got it!.

        $ranks = new Ranks();
        $db = $ranks->getWriteConnection();
        $db->begin();
        $db->update($ranks->getSource(), [
            'last_win',
            'reward_tag'
        ], [
            new \Phlacon\Db\RawValue('win'),
            new \Phalcon\Db\RawValue('week_tag')
        ]);
        // $sql = 'UPDATE ranks SET ranks.last_win = ranks.win, extras.reward_tag = extras.week_tag';
        $db->commit();

@cphalcon, I just find the RawValue Can be a powerful tool, much thanks